package com.dz.risk.controller;

import com.dz.risk.common.ResponseVO;
import com.dz.risk.pojo.domain.ListOfDefaultedBonds;
import com.dz.risk.pojo.model.PageModel;
import com.dz.risk.service.ListOfDefaultedBondsService;
import com.dz.risk.validation.Add;
import com.dz.risk.validation.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 违约债券名单接口控制层
 *
 * @author Doke
 * @date 2021/7/7 15:23
 */
@RestController
@RequestMapping("/dz-ftsp/stest/listOfDefaultedBonds")
@Api(tags = "违约债券名单Api")
public class ListOfDefaultedBondsController {

    private final ListOfDefaultedBondsService listOfDefaultedBondsService;

    @Autowired
    public ListOfDefaultedBondsController(ListOfDefaultedBondsService listOfDefaultedBondsService) {
        this.listOfDefaultedBondsService = listOfDefaultedBondsService;
    }

    @ApiOperation("新增违约债券名单")
    @PostMapping("/add")
    public ResponseVO add(@RequestBody @Validated({Add.class}) ListOfDefaultedBonds listOfDefaultedBonds) {
        return listOfDefaultedBondsService.add(listOfDefaultedBonds);
    }

    @ApiOperation("根据违约债卷ID删除信息")
    @ApiImplicitParam(name = "id", value = "违约债券名单Id", required = true, dataType = "String")
    @GetMapping("/deleteById")
    public ResponseVO deleteById(@RequestParam("id") String id) {
        listOfDefaultedBondsService.removeById(id);
        return ResponseVO.ok();
    }

    @ApiOperation("根据违约债券Id更新信息 ")
    @PostMapping("/updateById")
    public ResponseVO updateById(@RequestBody @Validated({Update.class}) ListOfDefaultedBonds listOfDefaultedBonds) {
        listOfDefaultedBondsService.updateByListOfDefaultedBondsId(listOfDefaultedBonds);
        return ResponseVO.ok();
    }

    @ApiOperation("分页查询违约债卷信息 ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页(默认 : 1)", dataType = "Integer"),
            @ApiImplicitParam(name = "rows", value = "显示条数(默认 : 10)", dataType = "Integer"),
            @ApiImplicitParam(name = "bondName", value = "债券名称", dataType = "Integer"),
            @ApiImplicitParam(name = "bondCode", value = "债卷代码", dataType = "Integer")
    })
    @GetMapping("/pageList")
    public ResponseVO pageList(PageModel pageModel, String bondName, String bondCode, Long beginDate, Long endDate) {
        return ResponseVO.ok(listOfDefaultedBondsService.pageList(pageModel, bondName, bondCode,beginDate,endDate));
    }


}
